import Immutable from 'immutable';
import { applyMiddleware, compose, createStore } from 'redux'
import { createRootReducer } from '../reducers'
import createMiddlewares from './middlewares'
import enhancers  from './enhancers'
import { composeWithDevTools } from 'redux-devtools-extension'
// ======================================================
// 实例化 Store
// ======================================================
export const store = (initState = Immutable.Map()) => {	
	const reduxStore = createStore(
		createRootReducer(),
		initState,
		// composeWithDevTools(
			applyMiddleware(...createMiddlewares),
			...enhancers
		// )
	);
	if (module.hot) {
		module.hot.accept('../reducers', () => {
			const nextReducer = require('../reducers')
			reduxStore.replaceReducer(nextReducer)
		})
	}
	return reduxStore;
}
export default store